package com.gxuwz.eschool;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

public class jiaoyiQueryActivity extends AppCompatActivity {
    //定义点击返回按钮
    private Button btn_back;

    private RecyclerView recyclerView_Jiaoyi;
    //适配器，列表绑定
    private JiaoyiAdapter adapter;
    //需要的适配器
    private String[] names = {"北校区送电通知！","水费、电费注意！","公文注意！","喝水注意！","胖猫注意！","吃饭注意！"};
    private String[] Time = {"2022-9-12 12:34","2022-9-12 12:34","2022-9-12 12:34","2022-9-12 12:34","2022-9-12 12:34","2022-9-12 12:34"};
    private String[] ID = {"001","002","003","004","005","006"};
    private String[] Free = {"-8","-10","-15","-7.5","-9","-13"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.jiaoyi_query);
        //去除默认标题栏
        ActionBar actionBar=getSupportActionBar();
        if(actionBar!=null){
            actionBar.hide();
        }

        // 初始化RecyclerView和适配器
        recyclerView_Jiaoyi = (RecyclerView) findViewById(R.id.recyclerView_jiaoyi);
        recyclerView_Jiaoyi.setLayoutManager(new LinearLayoutManager(this));

        //创建一个适配器实例
        adapter = new JiaoyiAdapter();
        //将适配器添加到列表控件上
        recyclerView_Jiaoyi.setAdapter(adapter);
        //方法区
        fanhui();
    }
    public void fanhui() {
        btn_back =  findViewById(R.id.btn_back);
        //返回首页,物理返回就行了
        btn_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();//默认的返回类型，等同于按下了物理返回键
            }
        });

    }

    // 交易记录的列表
//    List<Transaction> transactions = getTransactionsFromDatabaseOrApi(); // 获取交易记录
//    adapter = new TransactionAdapter(transactions); // 创建适配器实例并传入数据
//        recyclerViewTransactions.setAdapter(adapter); // 设置适配器

    // 这是一个假设的方法，用于从数据库或API获取交易记录
//    private List<Transaction> getTransactionsFromDatabaseOrApi() {
//        // ... 实现获取交易记录的逻辑 ...
//        return new ArrayList<>(); // 返回交易记录列表的示例，实际开发中你需要替换这部分
//    }

    //创建交易适配器

    //适配器等其他
    class JiaoyiAdapter extends RecyclerView.Adapter<jiaoyiQueryActivity.MyViewHolder> {

        @Override
        public jiaoyiQueryActivity.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(jiaoyiQueryActivity.this).inflate(R.layout.jiaoyi_list,null);
        MyViewHolder holder = new MyViewHolder(view);
            return holder;
        }

        @Override
        public void onBindViewHolder(@NonNull jiaoyiQueryActivity.MyViewHolder holder, int position) {
            holder.jiaoyi_name.setText(names[position]);
            holder.jiaoyi_Time.setText(Time[position]);
            holder.jiaoyi_ID.setText(ID[position]);
            holder.jiaoyi_Free.setText(Free[position]);
        }

        @Override
        public int getItemCount() {
            return names.length;
        }
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        TextView jiaoyi_Time,jiaoyi_name,jiaoyi_ID,jiaoyi_Free;
        //初始化linearLayout
        LinearLayout linearLayout;
        public MyViewHolder(View view) {
            super(view);
            jiaoyi_name = view.findViewById(R.id.jiaoyi_Name);
            jiaoyi_Time = view.findViewById(R.id.jiaoyi_Time);
            jiaoyi_ID = view.findViewById(R.id.jiaoyi_ID);
            jiaoyi_Free = view.findViewById(R.id.jiaoyi_Free);
        }
    }
}